import {CookiesS} from './storageUtils'
import constant from './constant'

let Auth = constant.Auth;
let session = {
    setToken(token) {
        CookiesS.set(Auth.AccessTokenKey, token.access_token);
        CookiesS.set(Auth.RefreshTokenKey, token.refresh_token);
        CookiesS.set(Auth.TokenTypeKey, token.token_type);
        CookiesS.set(Auth.TokenExpiresInKey, token.expires_in);// 秒
        CookiesS.set(Auth.TokenScopeKey, token.scope);
    },
    getAccessToken() {
        return CookiesS.get(Auth.AccessTokenKey);
    },
    getRefreshToken() {
        return CookiesS.get(Auth.RefreshTokenKey);
    },
    getTokenType() {
        return CookiesS.get(Auth.TokenTypeKey);
    },
    getTokenExpiresIn() {
        return CookiesS.get(Auth.TokenExpiresInKey);
    },
    getTokenScope() {
        return CookiesS.get(Auth.TokenScopeKey);
    },
    removeToken() {
        CookiesS.remove(Auth.AccessTokenKey);
        CookiesS.remove(Auth.RefreshTokenKey);
        CookiesS.remove(Auth.TokenTypeKey);
        CookiesS.remove(Auth.TokenExpiresInKey);
        CookiesS.remove(Auth.TokenScopeKey);
    }
}

export default session;
